package com.itheima.tanhua.interceptor;

import com.itheima.tanhua.pojo.db.user;

/**
 * @author 芝士雪豹
 * @create 2022/9/23/20:08
 *
 * 工具类:存储 拦截器 获取得到的信息 用户id 手机号 用户信息等
 */

public class userHolder {
    //创建存储对象的ThreadLocal
    public static ThreadLocal<user> threadLocal =new ThreadLocal<user>();
    //将用户数据存入ThreadLocal
    public static void set(user users){
        threadLocal.set(users);
    }
    //从当前线程获取用户对象
    public static user get(){
       return threadLocal.get();
    }
    //从当前线程获得用户id
    public static Long getId(){
        return threadLocal.get().getId();
    }
    //从当前线程获取用户手机号
    public static String getPhone(){
       return threadLocal.get().getMobile();
    }
    //线程的删除功能
    public static void remove(){
        threadLocal.remove();
    }


}
